#include <iostream>
using namespace std;
int main()
{
	int year,mon;
	cin>>year>>mon;
	if (year%4==0 && year%100!=0)
	{
		if (mon==2) cout<<29<<endl;
		else if (mon==8 || mon==10 || mon==12) cout<<31<<endl;
		else cout<<30<<endl;
	}
	else if(year%100==0 && year%400==0)
	{
		if (mon==2) cout<<29;
		else if (mon==8 || mon==10 || mon==12) cout<<31<<endl;
		else cout<<30<<endl;
	}
	else
	{
		if (mon==2) cout<<28;
		else if (mon==8 || mon==10 || mon==12) cout<<31<<endl;
		else cout<<30<<endl;
	}
	return 0;
}
